//
//  Localcollection.m
//  meituan
//
//  Created by apple on 16/5/20.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "Localcollection.h"
#import <CoreLocation/CoreLocation.h>
@interface Localcollection()<CLLocationManagerDelegate>
@property(nonatomic,strong)CLLocationManager *manager;
@property(nonatomic,assign)NSInteger inter;
@end
@implementation Localcollection
-(instancetype)init
{
    if (self = [super init]) {
        self.manager = [[CLLocationManager alloc]init];
        self.manager.delegate = self;
        self.inter = 0;
        self.manager.desiredAccuracy = kCLLocationAccuracyBest;
        [self.manager requestWhenInUseAuthorization];
        [self.manager startUpdatingLocation];

    }
    return self;

}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    self.inter = self.inter+1;

    CLLocation *locatoin = [locations objectAtIndex:0];
    if (self.inter==1) {
        [self.deleget gaveme:locatoin sucecess:YES error:nil];
    }
    [self.manager stopUpdatingLocation];
//    NSLog(@"cesi%f",self.location.coordinate.latitude);
    
}
//获取定位失败回调方法
#pragma mark - location Delegate
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
    NSLog(@"%@",error);
    [self.deleget gaveme:nil sucecess:NO error:error];
}


@end
